//
//  MainTabBarController.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/4/21.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//



#import "MainTabBarController.h"
#import "List_ViewController.h"
#import "MyListViewController.h"
#import "DataDownloadViewController.h"
#import "CarModel.h"

@interface MainTabBarController ()<CarModelDelegate>


@property (nonatomic,strong) CarModel *carlistModel;


@end



@implementation MainTabBarController


-(void)dealloc{

    [[NSNotificationCenter defaultCenter]  removeObserver:self name:@"CarNumberChange" object:nil];//移除通知
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabBar.backgroundColor = [UIColor whiteColor];
    self.tabBar.selectedImageTintColor = [UIColor colorWithRed:207/255.0 green:0 blue:13/255.0 alpha:1];
    self.delegate = self;
    
    
    
    
    
    //注册一个通知，用来监视购物车数量变化，及时更新购物车图标数字
    
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(carNumber:) name:@"CarNumberChange" object:nil];
    [self getCarNUMber];
}



- (void) carNumber:(NSNotification*)notification
{

    
    [self getCarNUMber];
    
}

- (void)getCarNUMber{
    
    self.carlistModel = [[CarModel alloc] init];
    _carlistModel.carModelDelegate = self;
    NSString *agentId = [[NSUserDefaults standardUserDefaults] objectForKey:@"userID"];
    if (agentId.length < 1) {
        
    }else{
    NSDictionary *dic = @{@"AgentID":agentId};
    NSMutableArray *array = [NSMutableArray array];
    [_carlistModel getCarList:array parameter:dic];
    }
    
}
- (void)getCarListEnd{
    
    UIViewController *controller = self.viewControllers[1];
    NSString *str = [NSString stringWithFormat:@"%@",self.carlistModel.Amount];
    if ([str isEqualToString:@""]||self.carlistModel.Amount ==nil ) {
        controller.tabBarItem.badgeValue = nil;
    }
    else{
    controller.tabBarItem.badgeValue = [NSString stringWithFormat:@"%@",self.carlistModel.Amount];
    }
    
}



- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    
    
    //    if (tabBarController.selectedIndex == 2) {
    
    //        MyListViewController *offlineCv = [[MyListViewController alloc] init];
    
    //        offlineCv.mainLineCV = self;
    
    //        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:offlineCv];
    
    //        nav.navigationBar.barTintColor = [UIColor colorWithRed:234/255.0 green:0 blue:86/255.0 alpha:1];
    
    //        [self presentViewController:nav animated:NO completion:nil];
    
    //    }
    
    
    
}
@end

